package kummer.wu;

import java.util.Comparator;

public class Record implements Comparable<Record>{
	public int id;
	public int lastTime;
	public int nextTime;
	private short familiarity;
	public short track;
	
	public short getFamiliarity()
	{
		return familiarity;
	}
	public void setFamiliarity(short familiarity) 
	{
		this.familiarity = familiarity;
	}
	public void addFamiliarity()
	{
		familiarity++;
		if(familiarity>=Config.ts.length)
		{
			familiarity--;
		}
	}
	public void subFamiliarity()
	{
		familiarity--;
		if(familiarity<0)
		{
			familiarity=0;
		}
	}
	public int getTS()
	{
		return Config.ts[familiarity];
	}
	public String getSInfo()
	{
		String str = "";
		short s = (short) (track & 0x3FFF);
		while(s!=0)
		{
			if((s&3)==3)
			{
				str+="O";
			}
			else if((s&3)==2)
			{
				str+="X";
			}
			else if((s&3)==0)
			{
				break;
			}
			s = (short) (s>>2);
		}
		return "["+familiarity + " " +str+"]";
	}
	public String getInfo()
	{
		return " id="+id+" lastTime ="+lastTime +" nastTime ="+ nextTime+" track= "+getSInfo()+" fami ="+familiarity;
	}
	
	public int compare(Record obj1, Record obj2) {
		if(obj1.nextTime!=obj2.nextTime)
		{
			return obj1.nextTime - obj2.nextTime;
		}
		else if(obj1.lastTime != obj2.lastTime)
		{
			return obj1.lastTime - obj2.lastTime;
		}
		else
		{
			return obj1.id  - obj2.id;
		}
		
	}
	@Override
	public int compareTo(Record another) {
		return compare(this, another);
	}
	
}
